It's been a while since I lastly posted here! I've been diving deeper into C# and Unity development, experimenting with game mechanics like player input systems, AI behavior trees, and controller support.
I've also been polishing parts of my personal website โ integrating clean code snippets, adding real-time script downloads, and building blog support to share insights like this one.
On the side, I'm preparing new VR and desktop game prototypes with a focus on clean architecture and optimization.
buttons_cs.js for copying code blocksHereโs a more complex script demonstrating coroutine handling and object pooling for bullets:
public class BulletPool : MonoBehaviour
{
public GameObject bulletPrefab;
public int poolSize = 20;
private Queue bulletPool;
void Start()
{
bulletPool = new Queue();
for (int i = 0; i < poolSize; i++)
{
GameObject bullet = Instantiate(bulletPrefab);
bullet.SetActive(false);
bulletPool.Enqueue(bullet);
}
}
public void FireBullet(Vector3 position, Vector3 direction)
{
if (bulletPool.Count == 0) return;
GameObject bullet = bulletPool.Dequeue();
bullet.transform.position = position;
bullet.transform.forward = direction;
bullet.SetActive(true);
StartCoroutine(DeactivateBullet(bullet, 3f));
}
private IEnumerator DeactivateBullet(GameObject bullet, float delay)
{
yield return new WaitForSeconds(delay);
bullet.SetActive(false);
bulletPool.Enqueue(bullet);
}
}